package com.bum.api.core.bo;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.beanutils.BeanDeclaration;
import org.apache.commons.configuration.beanutils.BeanHelper;
import org.apache.commons.configuration.beanutils.XMLBeanDeclaration;

import com.bum.api.core.bo.om.App;

public class DataBO {
	static XMLConfiguration	config;

	static {
		try {
			config = new XMLConfiguration("data.xml");
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
	}

	public static Map<String, App> loadApps() {
		int count = config.configurationsAt("apps.app").size();

		Map<String, App> apps = new LinkedHashMap<String, App>(count);
		for (int i = 0; i < count; i++) {
			try {
				BeanDeclaration dec = new XMLBeanDeclaration(config, "apps.app(" + i + ")");
				App app = (App) BeanHelper.createBean(dec, App.class);
				apps.put(app.getCode(), app);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		return apps;
	}
}
